<template>
  <div>
    <div v-if="!tbshow" style="margin-top: 20px">
      <el-radio-group v-model="nodeStatus" @change="getList" size="small">
        <el-radio-button label="start_node">已提交</el-radio-button>
        <el-radio-button label="user_node">已审核</el-radio-button>
      </el-radio-group>
    </div>
    <el-table :data="list" style="width: 100%" v-loading.body="listLoading"
              :row-class-name="tableRowClassName"
              @row-click="handRowClick"
    >
      <el-table-column prop="" width="50" label="#">
        <template slot-scope="scope" align="center"><span>{{scope.row.px}}</span></template>
      </el-table-column>
      <el-table-column align="center"  :label="tbshow?'待办事项':'申办事项' " prop="groupName">
        <template slot-scope="scope"><span  @click="showFlow(scope.row)" style="color: #cc0e7e; font-weight: bolder; cursor: pointer;">{{scope.row.groupName}}</span></template>
      </el-table-column>

      <el-table-column align="center" label="创建时间" prop="createdTime">
        <template slot-scope="scope"><span>{{scope.row.createdTime}} </span></template>
      </el-table-column>

      <el-table-column align="center" label="备件名称" prop="operatorName">
        <template slot-scope="scope"><span>{{scope.row.hiParams.partName}}</span></template>
      </el-table-column>
      <el-table-column align="center" label="发起人" prop="operatorName">
        <template slot-scope="scope"><span>{{scope.row.operatorName}}</span></template>
      </el-table-column>
      <el-table-column align="center" :label="tbshow?'待处理':'处理详情'" prop="nodeName">
        <template slot-scope="scope">
          <el-tag v-if="tbshow" style="cursor:pointer" @click.stop="auditRow(scope.row)"
                  :type="scope.row.nodeId | statusFilter">{{ scope.row.nodeName }}
          </el-tag>
          <el-tag v-else style="cursor:pointer" @click.stop="auditRow(scope.row)" :type="scope.row.nodeId | statusFilter">{{ scope.row.nodeName }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column v-if="!tbshow" align="center" label="处理结果" prop="operatorName">
        <template slot-scope="scope">
          <el-tag style="cursor:pointer" @click="showFlow(scope.row)"  :type="scope.row.exeNodeId,scope.row.hiParams.audit | endFilter">{{ scope.row.exeNodeId ,scope.row.hiParams.audit | end2Filter }}
          </el-tag></template>
      </el-table-column>
    </el-table>


    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.size"
                @pagination="getList"/>

    <flowShow ref="fshow"
    ></flowShow>
  </div>
</template>

<script>
  import {disableBtn, ERRS, SUCS} from '@/utils'
  import {fetchGet, updateOne} from '@/api/common'
  import Pagination from '@/components/Pagination'
  import flowShow from './flowShow'
  export default {
    name: 'tbAudit',
    components: {
      Pagination,flowShow
    },
    props: {
      nodeId: String,
      param: Object,
    },

    computed: {
      tbshow: {
        get: function () {
          return (this.nodeId == 'myHiTask' || this.nodeId == this.GLB.end_node )?false:true
        },
        set: function () {
        }
      }


    },
    filters: {
      statusFilter(status) {
        const statusMap = {
          start_node: 'text',
          end_node: 'info',
          user_node: 'primary',
          // published: 'primary',
          // deleted: 'warning'
        }
        return statusMap[status]
      },

      endFilter(status,too) {
        const statusMap = {
          start_node: 'primary',
          user_node: 'primary',
          end_node0: 'danger',
          end_node1: 'success',
          end_node: 'info',
        }
        let key=status+too
        return statusMap[key]
      },
      end2Filter(status,too) {
        const statusMap = {
          start_node: '待处理',
          start_nodeundefined: '待处理',
          user_node: '待处理',
          end_node0: '未通过',
          end_node1: '通过',
        }
        let key=status+too
        return statusMap[key]
      },
    },
    data: function () {
      return {
        typeStatus: 1,
        listLoading: false,
        //分页搜索
        total: 0,
        listQuery: {
          page: 1,
          size: 10, //limit条数
          searchText: '',
          partSourceType: '',
          partType: '',
          sort: {}
        },
        list: [],     //内容
        nodeStatus:this.GLB.start_node
        // tbshow:false


      }
    },

    watch: {
    },
    mounted() {
      this.getList()
    },

    methods: {
      //修改审查
      auditRow(row) {
        this.$emit('auditRow', row)
      },
      showFlow(row){
        this.$refs.fshow.getNodeInfo(row)
      },
      getList() {
        this.total = 0;
        this.listLoading = true;
        let url = '';
        if (this.nodeId == 'myHiTask') {
          console.log('myHiTask',this.nodeStatus)
          url = `flowable/hi/myHiTask?groupId=code_flowable&nodeId=${this.nodeStatus}`;
        } else if (this.nodeId == this.GLB.end_node) {
          url = ''
        } else {
          url = `flowable/ru/myTask?groupId=code_flowable&nodeId=${this.nodeId}`;
        }
        fetchGet(url).then(res => {
          if (res.code == 0) {
            let dat = res.data
            if (this.nodeId != 'myHiTask') {
              this.list = dat
            }else{
              this.list = dat.content
              this.listQuery.size = dat.size ? dat.size : this.listQuery.size//每页几条
              this.listQuery.page = dat.page ? dat.page : this.listQuery.page//当前页为第1页
              this.total=dat.totalElements
            }
            let insIndex = this.listQuery.size * (this.listQuery.page - 1);
            this.list = this.list.map((v, index) => {
              this.$set(v, 'px', insIndex + index + 1);
              // this.$set(v, 'roles',insIndex+index+1);
              //草稿无name
              if(this.nodeId==this.GLB.start_node){
                let hiParams = eval('('+v.opFormJson+')')
                v.hiParams.partName=hiParams.partName
              }
              this.px = insIndex + index + 1; //最大序号
              return v
            });
            // console.log(this.list)

            this.$nextTick()
          } else {
            $err(res.message)
          }
          this.listLoading = false
        })
      },
      handRowClick(row) {
        // this.tableRowClassName(row)
        this.$emit('handRowClick', row)
      },

      //当前行配色
      tableRowClassName(row) {
        if (row.row._id && row.row._id == this.param._id) {
          return 'success-row';
          // return 'warning-row';
        }
        return '';
      },

    }
  }
</script>

<style lang="scss">

</style>
